
package me.zhengjie.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.domain.AppWorkCoverPoint;
import me.zhengjie.service.AppWorkCoverPointService;
import me.zhengjie.service.dto.AppWorkCoverPointQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @website https://el-admin.vip
* @author IQW
* @date 2022-07-18
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "标记点管理管理")
@RequestMapping("/api/appWorkCoverPoint")
public class AppWorkCoverPointController {

    private final AppWorkCoverPointService appWorkCoverPointService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('appWorkCoverPoint:list')")
    public void exportAppWorkCoverPoint(HttpServletResponse response, AppWorkCoverPointQueryCriteria criteria) throws IOException {
        appWorkCoverPointService.download(appWorkCoverPointService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询标记点管理")
    @ApiOperation("查询标记点管理")
    @PreAuthorize("@el.check('appWorkCoverPoint:list')")
    public ResponseEntity<Object> queryAppWorkCoverPoint(AppWorkCoverPointQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(appWorkCoverPointService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增标记点管理")
    @ApiOperation("新增标记点管理")
    @PreAuthorize("@el.check('appWorkCoverPoint:add')")
    public ResponseEntity<Object> createAppWorkCoverPoint(@Validated @RequestBody AppWorkCoverPoint resources){
        return new ResponseEntity<>(appWorkCoverPointService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改标记点管理")
    @ApiOperation("修改标记点管理")
    @PreAuthorize("@el.check('appWorkCoverPoint:edit')")
    public ResponseEntity<Object> updateAppWorkCoverPoint(@Validated @RequestBody AppWorkCoverPoint resources){
        appWorkCoverPointService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除标记点管理")
    @ApiOperation("删除标记点管理")
    @PreAuthorize("@el.check('appWorkCoverPoint:del')")
    public ResponseEntity<Object> deleteAppWorkCoverPoint(@RequestBody Integer[] ids) {
        appWorkCoverPointService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}